﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MMDemo
{
    public partial class SearchDataForm : Form
    {
        public SearchDataForm()
        {
            InitializeComponent();
        }
        private string[] searchstringdata; 
        private int[] searchintdata;
        private int searchnum;
        private void Okbtn_Click(object sender, EventArgs e)
        {
            String temp = InputStrtext.Text;
            searchstringdata = temp.Split(',');
            searchintdata = new int[searchstringdata.Length];
            try
            {
                if (searchstringdata.Length > 13 || searchstringdata.Length < 5)
                {
                    MessageBox.Show("获得较佳的演示效果，请输入5-13个查找数据!");
                    return;
                }
                for (int i = 0; i < searchstringdata.Length; ++i)
                {
                     int tempint= Convert.ToInt32(searchstringdata[i]);
                     if (tempint > 99 || tempint < 1)
                     {
                         MessageBox.Show("获得较佳的演示效果，数据大小为1-99!");
                         return;
                     }
                     searchintdata[i] = tempint;
                }
            }
            catch
            {
                MessageBox.Show("输入的数据有误!");
                return;
            }
            PublicDataClass.IsInit = true;
            GlobalSearch.SearchData = searchintdata;
            this.Close();
        }

        private void RamCrebtn_Click(object sender, EventArgs e)
        {
            InputStrtext.Text = "";
            Random ran = new Random();
            searchnum = ran.Next(5, 14);
            for (int i = 0; i < searchnum; ++i)
            {
                if (i != 0)
                {
                    InputStrtext.Text += ",";
                }
                InputStrtext.Text += ran.Next(1, 100);
            }
        }

        protected override void WndProc(ref   Message m)
        {
            const int WM_SYSCOMMAND = 0x0112;
            const int SC_CLOSE = 0xF060;
            if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE)
            {
                PublicDataClass.IsInit = false;
                this.Close();
                return;
            }
            base.WndProc(ref m);
        }
    }

      
    
}
